/**
 * ajax_post
 * @param url string 地址
 * @param url obj or post string 数据
 * @param callback function 回调
 * @param errorback function 错误回调
 * */
var postWithLoading = function (url, params, callback, errorback) {
    layer.load({shade: [0.5, '#000']});
    $.post(url, params, function (data) {

        var thisData = data;
        if (typeof(data) != "object") {
            thisData = jQuery.parseJSON(data);
        }
        layer.closeAll("loading");
        if (thisData.status == 1) {
            layer.msg(thisData.msg, {icon: 1, shade: [0.5, '#000'], time: 1000});
            if (typeof(callback) == 'string') {
                setTimeout(function () {
                    eval(callback)
                }, 1000);
            } else if (typeof(callback) == 'object' || typeof(callback) == 'function') {
                setTimeout(function () {
                    callback(thisData)
                }, 1000);
            } else {
                //自动重刷页面
                setTimeout(function () {
                    window.location.reload();
                }, 1000);
            }
        } else {
            layer.alert(thisData.msg, {
                icon: 2, end: function (index) {
                    if (errorback != undefined) {
                        errorback(thisData);
                    }
                }
            });
        }
    }).error(function () {
        layer.closeAll("loading");
        layer.alert("系统出了小差，请稍后重试！", {icon: 2});
    });
};

/**
 * 发送手机验证码
 * @param mobilephone 手机号码
 * @param type
 */
var sendSMS = function (thisobj, mobilephone, type, params, callback) {

    postWithLoading(CONTEXT_PATH + "/backend/user/sendSMS", {mobilephone: mobilephone, type: type, params: params},
        function (data) {
            $(thisobj).attr("disabled", "disabled");
            if (typeof(callback) != 'undefined') {
                callback(data)
            }
        });

}

/**
 * 开启关闭
 * @param openUrl 开启url
 * @param stopUrl 关闭url
 * @param openMessage 开启提示消息
 * @param stopMessage 关闭提示消息
 * @param $this
 */
var stop_open = function (openUrl, stopUrl, openMessage, stopMessage, $this) {
    var href = $this.attr('data-href');
    var confirmStr = $this.attr("data-confirm");
    if (isNotBlank(confirmStr)) {
        layer.confirm(confirmStr, function (index) {
            $.post(href, null, function (data) {
                if (typeof (data) != 'object') {
                    data = $.parseJSON(data);
                }
                layer.close(index);
                if (data.status == 1 && data.msg == '停用成功') {
                    layer.msg(data.msg);
                    $this.html("启用");
                    $this.attr('data-href', CONTEXT_PATH + openUrl + data.content);
                    $this.attr('data-confirm', openMessage);
                    /* $(".default-btn-link-stop_open").html("启用");
                     $(".default-btn-link-stop_open").attr('data-href',CONTEXT_PATH + openUrl + data.content);
                     $(".default-btn-link-stop_open").attr('data-confirm', openMessage); */
                }
                else if (data.status == 1 && data.msg == '开启成功') {
                    layer.msg(data.msg);
                    $this.html("停用");
                    $this.attr('data-href', CONTEXT_PATH + stopUrl + data.content);
                    $this.attr('data-confirm', stopMessage);
                }
                else {
                    layer.msg("操作失败！");
                }
            });
        });
    }
    else {
        layer.msg(data.msg);
        layer.closeAll();
    }

}


/**
 * 上传
 * @param url 上传url
 * @param fd 文件FormData
 * @param callback
 * @param errorback
 *
 文件FormData获取方式
 var fd = new FormData();
 fd.append( "file", $input.files[0]);
 */
var uploadWithLoading = function (url, fd, callback, errorback) {
    layer.load({shade: [0.5, '#000']});
    $.ajax({
        type: "POST",
        url: url,
        data: fd,
        contentType: false,
        processData: false,
        cache: false,
        success: function (data) {
            var thisData = data;
            if (typeof(data) != "object") {
                thisData = jQuery.parseJSON(data);
            }
            layer.closeAll("loading");
            if (thisData.status == 1) {
                layer.msg(thisData.msg, {shade: [0.5, '#000'], time: 1000});
                if (callback != undefined) {
                    setTimeout(function () {
                        callback(thisData)
                    }, 1000);
                } else {
                    //自动重刷页面
                    setTimeout(function () {
                        window.location.reload();
                    }, 1000);
                }
            } else {
                layer.alert(thisData.msg, {
                    end: function (index) {
                        if (errorback != undefined) {
                            errorback(thisData);
                        }
                    }
                });
            }
        }
    }).error(function () {
        layer.closeAll("loading");
        layer.alert("系统出了小差，请稍后重试！", {icon: 2});
    });
};

/**
 * 上传图片并显示
 * @param viewContainer
 * @param inputName
 * @param width
 * @param height
 * @param multi
 * @returns {boolean}
 */
function uploadWithView(viewContainer, inputName, $fileInput, width, height, multi) {
    if (typeof (width) == 'undefined') {
        width = "50px";
    }
    if (typeof (height) == 'undefined') {
        height = "50px";
    }
    var fileName = $fileInput.val();
    if (fileName == "") {
        layer.msg("请选择要上传的图片");
        return false;
    }
    var file = $fileInput[0].files[0];
    var imageType = /image.*/;
    if (!file.type.match(imageType)) {
        layer.msg("不是图片，请选择图片");
        return false;
    }
    var fd = new FormData();

    if (typeof (multi) == "undefined")multi = false;
    var split = $("input[name='" + inputName + "']").val().split(',');
    if (multi && collectionLength(split) >= 9) {
        layer.msg("最多上传9张图片");
        return false;
    }

    fd.append("file", file);
    $.ajax({
        type: "POST",
        // url: "http://192.168.1.233:9900/upload_action/upload",
        url: CONTEXT_PATH + "/up/upload",
        data: fd,
        contentType: false,
        processData: false,
        cache: false,
        success: function (data) {
            if (typeof (data) != 'object') {
                data = $.parseJSON(data);
            }
            if (data.code == 1) {
                //获取图片path
                var path = data.viewPath;
                var imageId = parseInt(Math.random() * 1000000000000);
                var htmlRender = '<img height="' + height + '" width="' + width + '" src="' + path + '" id="img-' + imageId + '" />' +
                    '<a class="btn btn-link" id="deleteBtn-' + imageId + '">删除</a>';
                if (multi) {
                    var existImage = $("input[name='" + inputName + "']").val();
                    if (existImage != "")existImage = existImage + ",";
                    existImage += path;
                    $("input[name='" + inputName + "']").val(existImage);
                    $(viewContainer).append(htmlRender);

                } else {
                    $("input[name='" + inputName + "']").val(path);
                    $(viewContainer).html(htmlRender);
                }
                bindDeleteImage(imageId, inputName);
            } else {
                layer.msg('图片上传失败');
            }
        }
    });
}


/**
 * 上传文件并显示
 * @param viewContainer 回显到容器的选择器
 * @param inputName input隐藏域的name
 * @param $fileInput 上传文件input的jq对象
 * @param multi 是否支持多张上传
 * @param filetype 支持的文件类型 VIDEO,AUDIO,IMAGE
 * @returns {boolean}
 */
function uploadFileWithView(viewContainer, inputName, $fileInput, multi, filetype) {
    var fileName = $fileInput.val();
    if (fileName == "") {
        layer.msg("请选择要上传的文件");
        return false;
    }
    var file = $fileInput[0].files[0];
    var pattern = '';
    if (filetype == "VIDEO") {
        pattern = /\.(mp4|ogg|ogv|rmvb|rm|avi|mkv|mpeg|mpg|mid|wmv|mov|flv|swf|webm)$/i;
    } else if (filetype == "AUDIO") {
        pattern = /\.(mp3|wav)$/i;
    } else if (filetype == "IMAGE") {
        pattern = /\.(jpg|gif|png|bmp|jpeg)$/i;
    }
    if (!fileName.match(pattern)) {
        layer.msg("对不起，暂不支持该格式");
        return false;
    }
    var fd = new FormData();

    if (typeof (multi) == "undefined")multi = false;

    fd.append("file", file);
    $.ajax({
        type: "POST",
        url: CONTEXT_PATH + "/up/upload",
        data: fd,
        contentType: false,
        processData: false,
        cache: false,
        success: function (data) {
            if (typeof (data) != 'object') {
                data = $.parseJSON(data);
            }
            if (data.code == 1) {
                //获取图片path id="file-'+imageId+'" data-src="'+path+'"
                var path = data.viewPath;
                var fileId = parseInt(Math.random() * 1000000000000);
                var htmlRender = '<p><span id="file-' + fileId + '" data-src="' + path + '" style="line-height: 45px;">' +
                    '<span class="glyphicon glyphicon-file"  aria-hidden="true" ></span> ' + path + '</span>' +
                    '<a class="btn btn-link" id="deleteBtn-' + fileId + '">删除</a></p>';
                if (multi) {
                    var existFile = $("input[name='" + inputName + "']").val();
                    if (existFile != "")existFile = existFile + ",";
                    existFile += path;
                    $("input[name='" + inputName + "']").val(existFile);
                    $(viewContainer).append(htmlRender);

                } else {
                    $("input[name='" + inputName + "']").val(path);
                    $(viewContainer).html(htmlRender);
                }
                bindDeleteFile(fileId, inputName);
            } else {
                layer.msg('文件上传失败');
            }
        }
    });
}
/**上传文件删除*/
function bindDeleteFile(id, inputName) {
    $("#deleteBtn-" + id).on("click", function (e) {
        var fileUrl = $("#file-" + id).data("src");
        var existFile = $("input[name='" + inputName + "']").val();
        existFile = existFile.replace(fileUrl + ",", "");
        existFile = existFile.replace("," + fileUrl, "");
        existFile = existFile.replace(fileUrl, "");
        $("input[name='" + inputName + "']").val(existFile);
        $("#file-" + id).parent().remove();
        $(this).remove();
    });
}
/**图片删除*/
function bindDeleteImage(id, inputName) {
    $("#deleteBtn-" + id).on("click", function (e) {
        var imageUrl = $("#img-" + id).attr("src");
        var existImage = $("input[name='" + inputName + "']").val();
        existImage = existImage.replace(imageUrl + ",", "");
        existImage = existImage.replace("," + imageUrl, "");
        existImage = existImage.replace(imageUrl, "");
        $("input[name='" + inputName + "']").val(existImage);
        $("#img-" + id).remove();
        $(this).remove();

    });
}

/**select自动选择*/
function autoSelectSetValue() {
    $(".select-auto-set-value").each(function (i, e) {
        var $e = $(e);
        var value = $e.data("value");
        var array = $e.find("li");
        if (array.length == 0) {
            array = $e.find("option");
        }
        array.each(function (i, item) {
            var $item = $(item);
            var itemValue = $item.data("value");
            if (typeof ( itemValue) == "undefined")
                itemValue = $item.val();
            if (typeof (itemValue) != "undefined") {
                if (itemValue == value) {
                    $item.addClass("on");
                    $item.attr("selected", "selected");
                }
                else {
                    $item.removeClass("on");
                    $item.removeAttr("selected");
                }
            }
        });
    });
}
function defaultLinkFunction(href,gotoUrl,callbackFn,errorfn,confirm){
    if (isNotBlank(confirm)) {
        layer.confirm(confirm, function (index) {
            postWithLoading(href, null, function (data) {
                if (isNotBlank(gotoUrl))window.location.href = gotoUrl;
                else if (typeof (callbackFn) == "string" && isNotBlank(callbackFn)) {
                    eval(callbackFn);
                } else if (typeof (callbackFn) == "function" || typeof (callbackFn) == "object") {
                    callbackFn();
                }
                else {
                    window.location.reload();
                }
            }, function () {
                if (isNotBlank(gotoUrl))window.location.href = gotoUrl;
                else if (typeof (errorfn) == "string" && isNotBlank(errorfn)) {
                    eval(callbackFn);
                } else if (typeof (errorfn) == "function" || typeof (errorfn) == "object") {
                    callbackFn();
                }

            });
        });
    } else {
        postWithLoading(href, null, function () {
            if (isNotBlank(gotoUrl))window.location.href = gotoUrl;
            else if (typeof (callbackFn) == "string" && isNotBlank(callbackFn)) {
                eval(callbackFn);
            } else if (typeof (callbackFn) == "function" || typeof (callbackFn) == "object") {
                callbackFn();
            }
            else {
                window.location.reload();
            }
        }, function () {
            if (isNotBlank(gotoUrl))window.location.href = gotoUrl;
            else if (typeof (errorfn) == "string" && isNotBlank(errorfn)) {
                eval(callbackFn);
            } else if (typeof (errorfn) == "function" || typeof (errorfn) == "object") {
                callbackFn();
            }
        });
    }
}

function defaultBtnLinkFunction(e, $this, callbackFn,errorfn) {
    e.preventDefault();
    var href = $this.data('href');
    var gotoUrl = $this.data('goto');
    if(typeof (callbackFn) == 'undefined' || callbackFn == null){
        callbackFn = $this.data('func');
    }
    if(typeof (errorfn) == 'undefined' || errorfn == null){
        errorfn = $this.data('errorfn');
    }
    var confirm = $this.data('confirm');

    defaultLinkFunction(href,gotoUrl,callbackFn,errorfn,confirm);
}
/**默认ajax事件绑定*/
function defaultBtnLinkRebind() {
    $(".default-btn-link").unbind();
    $(".default-btn-link").on('click', function (e) {
        defaultBtnLinkFunction(e, $(this));
    });

}

function defaultOpenLinkFunction(e, $this, func) {
    e.preventDefault();
    var href = $this.data('href');
    var gotoUrl = $this.data('goto');
    if (typeof (func) == "undefined") {
        func = $this.data('func');
    }
    if (typeof (href) != "undefined") {

        layer.open({
            type: 2,
            area: ['700px', '530px'],
            fixed: false, //不固定
            maxmin: true,
            content: href,
            end: function () {
                if (isNotBlank(gotoUrl))window.location.href = gotoUrl;
                else if (typeof (func) == "string" && isNotBlank(func)) {
                    eval(func);
                } else if (typeof (func) == "function" || typeof (func) == "object") {
                    func();
                }
            }

        });
    }

}
/**打开layer窗口*/
function defaultOpenLayerRebind(){
    $(".default-btn-open-layer").unbind().on('click',function(e){
        defaultOpenLinkFunction(e,$(this));
    })
}

/**表单提交*/
function btnSubmitRebind() {
    $(".btn-submit").unbind().on('click', function (e) {
        e.preventDefault();
        var $this = $(this);
        var $form = $(this).parents("form");
        var validatorvar = $this.data("validatorvar");
        var userType = $this.data("userType");
        if (typeof (validatorvar) != "undefined") {
            eval("var flag = " + validatorvar + ".subByJs();");
            if (typeof (flag) != undefined) {
                if (flag == false) return;
            }
        }
        if ($form && $form != 0) {
            var action = $this.data("action");
            if (typeof (action) == 'undefined') {
                action = $form.attr("action");
            }
            var ref = $this.data("refer");
            var func = $this.data("func");
            var formData = $form.serialize();
            console.log(formData);
/*
            formData = encodeURI(formData);
            console.log(formData);
*/
            postWithLoading(action, formData, function (data) {
                if (ref) {
                    window.location.href = ref;
                } else if (func) {
                    eval(func);
                }
            });
        }
    });

}

/**回车键自动提交表单提交*/
function enterKeySubmitRebind(){
    //回车提交表单
    $('body').unbind('keydown').bind('keydown', function (e) {
        if (e.keyCode == 13) {
            var target = e.target;
            if(typeof (target)!="undefined"){
                var form = $(target).parents('form');
                if(typeof (form) != 'undefined'){
                    var btn = $(form).find(".btn-submit");
                    if(typeof (btn) != "undefined"){
                        $(target).blur();
                        $(btn).click();
                    }
                }
            }
        }
    });
}
/**取消回车键所有绑定*/
function enterKeySubmitUnbind(){
    $('body').unbind('keydown');
}

/**提交页面异步刷新*/
function btnSubmitAsyncRebind() {
    $(".btn-submit-yz").unbind();
    $(".btn-submit-yz").on('click', function (e) {
        e.preventDefault();
        var $this = $(this);
        var $form = $(this).parents("form");
        var validatorvar = $this.data("validatorvar");
        if (typeof (validatorvar) != "undefined") {
            eval("var flag = " + validatorvar + ".subByJs();");
            if (typeof (flag) != undefined) {
                if (flag == false) return;
            }
        }
        if ($form && $form != 0) {
            var action = $form.attr("action");
            var ref = $this.data("refer");
            $.post(action, $form.serialize(), function (data) {
                if (typeof(data) != "object") {
                    data = jQuery.parseJSON(data);
                }
                if (data.status == 1) {
                    if (ref) {
                        layer.msg(data.msg);
                        redirectPage(ref);
                    } else {
                        backAsync();
                    }
                }
                else {
                    layer.msg(data.msg);
                }
            });
        }
    });
}

/** checkBox 跳转定义 */
function infoBtnLinkRebind() {
    $(".info-btn-link").unbind().on('click', function (e) {
        e.preventDefault();
        var $this = $(this);
        layer.confirm($(this.data($this.data('msg'))));
    });
}

/** checkBox 跳转定义 */
function checkBtnLinkRebind() {
    $(".check-btn-link").unbind().on('click', function (e) {
        e.preventDefault();
        var $this = $(this);
        var href = $this.data('href');
        var func = $this.data('func');
        if ($this.data('for').length > 0 && $($this.data('for')).length > 0) {
            var data = $($this.data('for')).serialize();
            if (isNotBlank(data)) {
                if (href.indexOf('?') == -1)href += "?" + data;
                else href += "&" + data;
            }
            layer.confirm($this.data('confirm') != undefined ? $this.data('confirm') : "确定要批量做改操作么?", function (index) {
                if (typeof(func) != 'undefined') {
                    postWithLoading(href, null, func);
                }
                else {
                    postWithLoading(href, null);
                }

            });
        } else {
            layer.msg($this.data('unchecked') != undefined ? $this.data('unchecked') : "请先选择记录!");
        }
    });
}
/**导入文件事件绑定*/
function importExcelFileRebind() {
    $(".import-excel-file").on('change', function () {
        var url = $(this).data('url');
        impExcel(url, this);
    });
}

/**导入*/
function impExcel(url, thisobj) {
    var file = $(thisobj)[0].files[0];
    var fd = new FormData();
    fd.append("file", file);
    $(this).val("");

    uploadWithLoading(url, fd, function (data) {
        if (data.status == 1) {
            window.location.href = CONTEXT_PATH + "/backend/import/import_log?uid=" + data.content;
        }
    });
}
/**单图上传*/
function singleImageUploadRebind() {
    $(".btn-update-single-image").unbind();
    $(".btn-update-single-image").on('click', function (e) {
        e.preventDefault();
        var $this = $(this);
        var viewContainer = $this.data("viewcontainer");
        var inputName = $this.data("inputname");
        var $fileInput = $($this.data("fileinput"));
        var width = $this.data("width");
        var height = $this.data("height");
        uploadWithView(viewContainer, inputName, $fileInput, width, height, false);
    });

}
/**图片上传*/
function imageUploadRebind() {
    $(".btn-update-image").unbind();
    $(".btn-update-image").on('click', function (e) {
        e.preventDefault();
        var $this = $(this);
        var multi = $this.data("multi") == '1';
        var maxfiles = $this.data('maxfiles');
        var viewContainer = $this.data("viewcontainer");
        var inputName = $this.data("inputname");
        var $fileInput = $($this.data("fileinput"));
        var width = $this.data("width");
        var height = $this.data("height");
        var $inputhidden = $("input[name='" + inputName + "']");
        if ($inputhidden.length != 0) {
            var files = $inputhidden.val().split(",");
            if (typeof (maxfiles) == "string") {
                try {
                    maxfiles = parseInt(maxfiles);
                } catch (e) {
                    maxfiles = 8;	//默认做大值是8张
                }

            }
            if (typeof(maxfiles) == 'number') {
                if (maxfiles <= files.length) {
                    layer.msg("对不起，最多能上传" + maxfiles + "张图片");
                    return false;
                }
            }
        }
        uploadWithView(viewContainer, inputName, $fileInput, width, height, multi);

    });
}

function selectAll() {
    $(".selectAll").unbind();
    $(".selectAll").on('click', function (e) {
        $("input[name='id']").attr("disabled", "disabled");
    });
}

/**
 * 异步跳转公共方法
 */
function linkAsyncRebind() {
    $(".link-async").unbind().on('click', function (e) {
        var url = $(this).data("url");
        if (isNotBlank(url)) {
            redirectPage(url);
        }
    });
}

function fileUploadRebind() {
    $(".btn-update-file").unbind();
    $(".btn-update-file").on('click', function (e) {
        e.preventDefault();
        var $this = $(this);
        var multi = $this.data("multi") == '1';
        var viewContainer = $this.data("viewcontainer");
        var inputName = $this.data("inputname");
        var $fileInput = $($this.data("fileinput"));
        var filetype = $this.data("filetype");
        uploadFileWithView(viewContainer, inputName, $fileInput, multi, filetype);
    });
}

/**checkbox在选择和取消时出发的请求动作*/
function btnCheckboxSelectCancelLinkRebind(){
    $(".btn-checkbox-select-cancel").unbind().on('change',function(e){
        var $this = $(this);
        var checked = this.checked == true ;
        var href;
        if(checked){
            href = $this.data("select-href");
        } else {
            href = $this.data("cancel-href");
        }
        console.log(checked);
        console.log(href);
        var func = $this.data('func');
        var gotoUrl = $this.data('gotoUrl');
        var confirm = $this.data('confirm');
        var errorfn = $this.data('errorfn');
        defaultLinkFunction(href,gotoUrl,func,errorfn,confirm)
    });

}

function commonRebind() {
    autoSelectSetValue();
    defaultBtnLinkRebind();
    infoBtnLinkRebind();
    btnSubmitRebind();
    enterKeySubmitRebind();
    /**异步提交*/
    btnSubmitAsyncRebind();
    /**异步跳转*/
    linkAsyncRebind();
    defaultOpenLayerRebind();
    checkBtnLinkRebind();
    btnCheckboxSelectCancelLinkRebind();
    importExcelFileRebind();
    singleImageUploadRebind();
    imageUploadRebind();
    fileUploadRebind();
    selectAll();
}


$(function () {
    commonRebind();
});

/**
 * 异步跳转
 */
function redirectPage(url) {
    if (url == "/backend/main") window.location.href = url;
    else
        $("#main_body").load(url, {timestamp: new Date().getTime()}, function (data, status) {
            if (data.indexOf("ajaxRequestSessionTimeOut") != -1) {
                window.location.href = "/login";
                return;
            }
            if (status == "error") {
                window.location.href = "/backend/main";
            }
            window.scrollTo(0, 0);
            $("input[name='PREREFER_URL']").val($("input[name='REFER_URL']").val());
            $("input[name='REFER_URL']").val($("input[name='THIS_URL']").val());
            $("input[name='THIS_URL']").val(url);
            if (typeof (layer) != 'undefined')
                layer.closeAll();
            commonRebind();
        });
}
/**
 * 异步回退
 */
function backAsync() {
    var url = $("input[name='REFER_URL']").val();
    if (url == "/backend/main") window.location.href = url;
    else
        $("#main_body").load(url, {timestamp: new Date().getTime()}, function () {
            window.scrollTo(0, 0);
            $("input[name='REFER_URL']").val($("input[name='PREREFER_URL']").val());
            $("input[name='THIS_URL']").val(url);
            if (typeof (layer) != 'undefined')
                layer.closeAll();
            commonRebind();
        });
}
/**
 * 刷新*/
function refreshAsync() {
    var url = $("input[name='THIS_URL']").val();
    redirectPage(url);
}

function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}

Date.prototype.plusSecond = function (second) {
    var time = this.getTime();
    this.setTime(time + second * 1000);
    return this;
};

Date.prototype.plusMinute = function (minute) {
    var time = this.getTime();
    this.setTime(time + minute * 1000 * 60);
    return this;
};

Date.prototype.plusHour = function (hour) {
    var time = this.getTime();
    this.setTime(time + hour * 1000 * 60 * 60);
    return this;
};

Date.prototype.plusDay = function (day) {
    var time = this.getTime();
    this.setTime(time + day * 1000 * 60  * 60 * 24);
    return this;
};

Date.prototype.plusMonth = function (month) {
    var time = this.getTime();
    this.setTime(time + month * 1000 * 60  * 60 * 24 * 30);
    return this;
};

// timeType 1按分钟  2按小时  3按天
function buildFullDateList ( end ,timeType){
    var startDate;
    var endDate;
    if(timeType == 1){
        end = end + ":59.999";
        endDate = new Date(end);
        startDate = new Date(end).plusHour(-1);
    } else if(timeType == 2){
        end = end + ":59:59.999";
        endDate = new Date(end);
        startDate = new Date(end).plusDay(-1);
    } else {
        end = end + " 23:59:59.999";
        endDate = new Date(end);
        startDate = new Date(end).plusMonth(-1);
    }
    var list= {};
    while (startDate.compare(endDate) < 0){
        if(timeType == 1){
            list[startDate.format('yyyy-MM-dd HH:mm')] = 0;
            startDate.plusMinute(1);
        } else if(timeType == 2){
            list[startDate.format('yyyy-MM-dd HH')] = 0;
            startDate.plusHour(1);
        } else {
            list[startDate.format('yyyy-MM-dd')] = 0;
            startDate.plusDay(1);
        }
    }
    return list;
}